﻿using System;
using System.Data;
using System.Collections.Generic;
using RealTimePriceFetchService.Model;

namespace RealTimePriceFetchService.BLL
{
    /// <summary>
    /// 业务逻辑类RealTimeStockInfoBLL 的摘要说明。
    /// </summary>
    public class RealTimeStockInfoBLL
    {
        private readonly RealTimePriceFetchService.DAL.RealTimeStockInfoDAL dal = new RealTimePriceFetchService.DAL.RealTimeStockInfoDAL();
        public RealTimeStockInfoBLL()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(RealTimePriceFetchService.Model.RealTimeStockInfoModel model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(RealTimePriceFetchService.Model.RealTimeStockInfoModel model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {
            dal.Delete(ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RealTimePriceFetchService.Model.RealTimeStockInfoModel GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<RealTimePriceFetchService.Model.RealTimeStockInfoModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<RealTimePriceFetchService.Model.RealTimeStockInfoModel> modelList = new List<RealTimePriceFetchService.Model.RealTimeStockInfoModel>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                RealTimePriceFetchService.Model.RealTimeStockInfoModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new RealTimePriceFetchService.Model.RealTimeStockInfoModel();
                    if (ds.Tables[0].Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[n]["ID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["StockCode"].ToString() != "")
                    {
                        model.StockCode = int.Parse(ds.Tables[0].Rows[n]["StockCode"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["CurrentPrice"].ToString() != "")
                    {
                        model.CurrentPrice = decimal.Parse(ds.Tables[0].Rows[n]["CurrentPrice"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["CurrentCount"].ToString() != "")
                    {
                        model.CurrentCount = int.Parse(ds.Tables[0].Rows[n]["CurrentCount"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy1Price"].ToString() != "")
                    {
                        model.Buy1Price = decimal.Parse(ds.Tables[0].Rows[n]["Buy1Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy1Count"].ToString() != "")
                    {
                        model.Buy1Count = int.Parse(ds.Tables[0].Rows[n]["Buy1Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy2Price"].ToString() != "")
                    {
                        model.Buy2Price = decimal.Parse(ds.Tables[0].Rows[n]["Buy2Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy2Count"].ToString() != "")
                    {
                        model.Buy2Count = int.Parse(ds.Tables[0].Rows[n]["Buy2Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy3Price"].ToString() != "")
                    {
                        model.Buy3Price = decimal.Parse(ds.Tables[0].Rows[n]["Buy3Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy3Count"].ToString() != "")
                    {
                        model.Buy3Count = int.Parse(ds.Tables[0].Rows[n]["Buy3Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy4Price"].ToString() != "")
                    {
                        model.Buy4Price = decimal.Parse(ds.Tables[0].Rows[n]["Buy4Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy4Count"].ToString() != "")
                    {
                        model.Buy4Count = int.Parse(ds.Tables[0].Rows[n]["Buy4Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy5Price"].ToString() != "")
                    {
                        model.Buy5Price = decimal.Parse(ds.Tables[0].Rows[n]["Buy5Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Buy5Count"].ToString() != "")
                    {
                        model.Buy5Count = int.Parse(ds.Tables[0].Rows[n]["Buy5Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale1Price"].ToString() != "")
                    {
                        model.Sale1Price = decimal.Parse(ds.Tables[0].Rows[n]["Sale1Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale1Count"].ToString() != "")
                    {
                        model.Sale1Count = int.Parse(ds.Tables[0].Rows[n]["Sale1Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale2Price"].ToString() != "")
                    {
                        model.Sale2Price = decimal.Parse(ds.Tables[0].Rows[n]["Sale2Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale2Count"].ToString() != "")
                    {
                        model.Sale2Count = int.Parse(ds.Tables[0].Rows[n]["Sale2Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale3Price"].ToString() != "")
                    {
                        model.Sale3Price = decimal.Parse(ds.Tables[0].Rows[n]["Sale3Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale3Count"].ToString() != "")
                    {
                        model.Sale3Count = int.Parse(ds.Tables[0].Rows[n]["Sale3Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale4Price"].ToString() != "")
                    {
                        model.Sale4Price = decimal.Parse(ds.Tables[0].Rows[n]["Sale4Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale4Count"].ToString() != "")
                    {
                        model.Sale4Count = int.Parse(ds.Tables[0].Rows[n]["Sale4Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale5Price"].ToString() != "")
                    {
                        model.Sale5Price = decimal.Parse(ds.Tables[0].Rows[n]["Sale5Price"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Sale5Count"].ToString() != "")
                    {
                        model.Sale5Count = int.Parse(ds.Tables[0].Rows[n]["Sale5Count"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["CurrentTime"].ToString() != "")
                    {
                        model.CurrentTime = DateTime.Parse(ds.Tables[0].Rows[n]["CurrentTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}
